package day06;

import java.io.RandomAccessFile;
import java.util.Scanner;

import org.junit.Test;

/**
 * 创建一个文件"note.txt",然后通过控制台输入的每一行字符串都按行写入到
 * note.txt中。当输入的字符串为"exit"时退出程序。
 * @author Bonnie
 *
 */
public class Test09 {
	@Test
	public void test() throws Exception {
		Scanner console = new Scanner(System.in);
		RandomAccessFile raf = new RandomAccessFile("note.txt", "rw");
		System.out.println("请输入字符串（exit退出）：");
		while (true) {
			String str = console.next();
			if (str.equals("exit")) {
				System.out.println("程序结束");
				break;
			} else {
				byte[] bs = str.getBytes();
				raf.write(bs);
			}
		}
		raf.close();
		console.close();
	}
}
